package com.tengju.data.infrastructure.repository.data.report;

import com.tengju.data.domain.model.analysis.Row;
import com.tengju.data.domain.model.report.secmonth.SecMonthReportRepository;
import com.tengju.data.infrastructure.persistence.mybatis.mapper.data.custom.SecMonthReportMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author chenhang
 * @Date 2021/7/12
 */
@Repository
@Slf4j
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class SecMonthReportRepositoryImpl implements SecMonthReportRepository {

    private final SecMonthReportMapper secMonthReportMapper;

    @Override
    public List<Row> profitAnalysis(Long idCode, Integer month) {
        List<Map<String,Object>> result = secMonthReportMapper.profitAnalysis(idCode,month);
        if (CollectionUtils.isEmpty(result)) {
            return Collections.emptyList();
        }
        return result.stream()
                .map(Row::new)
                .collect(Collectors.toList());
    }

    @Override
    public List<Row> profitDistributedAnalysis(Long idCode, Integer month) {
        List<Map<String,Object>> result = secMonthReportMapper.profitDistributedAnalysis(idCode,month);
        if (CollectionUtils.isEmpty(result)) {
            return Collections.emptyList();
        }
        return result.stream()
                .map(Row::new)
                .collect(Collectors.toList());
    }

    @Override
    public List<Row> achievementAnalysis(Long idCode, Integer month) {
        List<Map<String,Object>> result = secMonthReportMapper.achievementAnalysis(idCode,month);
        if (CollectionUtils.isEmpty(result)) {
            return Collections.emptyList();
        }
        return result.stream()
                .map(Row::new)
                .collect(Collectors.toList());
    }

    @Override
    public List<Row> brandGmvAnalysis(Long idCode, Integer month) {
        List<Map<String,Object>> result = secMonthReportMapper.brandGmvAnalysis(idCode,month);
        if (CollectionUtils.isEmpty(result)) {
            return Collections.emptyList();
        }
        return result.stream()
                .map(Row::new)
                .collect(Collectors.toList());
    }

    @Override
    public List<Row> teamRegionAnalysis(Long idCode, Integer month) {
        List<Map<String,Object>> result = secMonthReportMapper.teamRegionAnalysis(idCode,month);
        if (CollectionUtils.isEmpty(result)) {
            return Collections.emptyList();
        }
        return result.stream()
                .map(Row::new)
                .collect(Collectors.toList());
    }

    @Override
    public List<Row> teamAnalysis(Long idCode, Integer month) {
        List<Map<String,Object>> result = secMonthReportMapper.teamAnalysis(idCode,month);
        if (CollectionUtils.isEmpty(result)) {
            return Collections.emptyList();
        }
        return result.stream()
                .map(Row::new)
                .collect(Collectors.toList());
    }

    @Override
    public List<Row> listTeamUserTop(Long idCode, Integer month) {
        List<Map<String,Object>> result = secMonthReportMapper.listTeamUserTop(idCode,month);
        if (CollectionUtils.isEmpty(result)) {
            return Collections.emptyList();
        }
        return result.stream()
                .map(Row::new)
                .collect(Collectors.toList());
    }

    @Override
    public List<Row> listTeamUser(Long idCode, Integer month) {
        List<Map<String,Object>> result = secMonthReportMapper.listTeamUser(idCode,month);
        if (CollectionUtils.isEmpty(result)) {
            return Collections.emptyList();
        }
        return result.stream()
                .map(Row::new)
                .collect(Collectors.toList());
    }
}
